package org.design.strategyPattern;

import java.util.List;

/**
 * InsertionSort
 *
 * @author 樊温军
 * @date 2025/6/24 上午11:03
 */
public class InsertionSortAlgorithm implements AlgorithmStrategy {
    @Override
    public void sort(List<Integer> arr) {
        for (int i = 0; i < arr.size(); i++) {
            for (int j = i + 1; j > 0 && j < arr.size(); j--) {
                if (arr.get(j) < arr.get(j - 1)) {
                    int temp = arr.get(j);
                    arr.set(j, arr.get(j - 1));
                    arr.set(j - 1, temp);
                }
            }
        }
    }
}
